﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TreeSharp;

namespace FelMaster.Classes.Priest
{
    public class Shadow :TalentBase
    {
        public override string KeySpell
        {
            get { return "Mind Flay"; }
        }

        private int ShadowOrbs
        {
            get
            {
                return SC.PlayerCountBuff("Shadow Orb");
            }
        }

        public override TreeSharp.Composite SingleRotation
        {
            get
            {
                return new PrioritySelector(
                    //dont break mind flay early
                    new Decorator(x => SC.PlayerIsChanneling, new TreeSharp.Action(a => SC.Log("Channeling - don't break it."))),

                    SC.CastSpell("Mind Blast", a => ShadowOrbs > 0, "Mind Blast to refresh buff"),
                    SC.CastDebuff("Shadow Word: Pain", a => SC.TargetDebuffTimeLeft("Shadow Word: Pain") < SC.GCD+0.5, "Shadow word pain"),
                    SC.CastDebuff("Devouring Plague", a => SC.TargetDebuffTimeLeft("Devouring Plague") < SC.GCD + 1.0, "Devouring Plague"),
                    SC.CastDebuff("Vampiric Touch", a => SC.TargetDebuffTimeLeft("Vampiric Touch") < SC.CastTime("Vampiric Touch") + 2.5, "Vampiric Touch"),
                    SC.CastSpell("Archangel", a => SC.PlayerCountBuff("Dark Evangelism") >= 5 && SC.TargetDebuffTimeLeft("Vampiric Touch") > 5 && SC.TargetDebuffTimeLeft("Devouring Plague") > 5, "Archangel"),
                    SC.CastSpell("Shadow Word: Death", a => Me.CurrentTarget.HealthPercent <= 25, "Shadow Word Death"),
                    SC.CastSpell("Shadowfiend", a => true, "Shadowfiend"),
                    SC.CastSpell("Mind Blast", a => true, "Mind Blast"),
                    SC.CastSpell("Shadow Word: Death", a => Me.ManaPercent < 0.1, "Shadow Word Death to get mana"),
                    SC.ChannelSpell("Mind Flay", a => true, "Mind Flay"),
                    SC.CastSpell("Shadow Word: Death", a => Me.IsMoving, "Shadow Word Death while moving"),
                    SC.CastSpell("Devouring Plague", a => Me.IsMoving && Me.ManaPercent > 0.1, "Devouring Plague spam while moving"),

                    //tweaked s.t. it's only cast when necessary
                    SC.CastSpell("Dispersion", a => (Me.ManaPercent < 0.3 && !SC.PlayerHasBuff("Dark Angel")), "Dispersion")
                );
            }
        }

        public override TreeSharp.Composite PVPRotation
        {
            get { throw new NotImplementedException(); }
        }

        public override TreeSharp.Composite PVERotation
        {
            get { return SingleRotation; }
        }

        public override TreeSharp.Composite Buffs
        {
            get
            {
                return new PrioritySelector(
                    //adding some healing logic, just in case.
                    SC.CastSpell("Flash Heal", a => Me.HealthPercent < (Me.Combat ? 10 : 50), "Emergency flash heal"),

                    SC.CastBuff("Inner Fire", a => true, "Inner Fire"),
                    SC.CastRaidBuff("Power Word: Fortitude", a => true, "Fortitude"),
                    SC.CastRaidBuff("Shadow Protection", a => true, "Shadow Protection"),
                    SC.CastBuff("Shadowform", a => Me.HealthPercent >= 10, "Shadow Form"),
                    SC.CastBuff("Vampiric Embrace", a => true, "Vampiric Embrace"),
                    SC.CastSpell("Dispersion", a => Me.ManaPercent < 0.7 && !Me.Combat, "Dispersion")
                );
            }
        }

        public override string Name
        {
            get { return "SimCraft's Shadow Priest T11N"; }
        }
    }
}
